var t = require;
var e = module;
var o = exports;
var a,
    i =
        (this && this.__extends) ||
        ((a = function (t, e) {
            return (a =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                })(t, e);
        }),
        function (t, e) {
            a(t, e);
            function o() {
                this.constructor = t;
            }
            t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o());
        }),
    n =
        (this && this.__decorate) ||
        function (t, e, o, a) {
            var i,
                n = arguments.length,
                r = n < 3 ? e : null === a ? (a = Object.getOwnPropertyDescriptor(e, o)) : a;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, a);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (i = t[s]) && (r = (n < 3 ? i(r) : n > 3 ? i(e, o, r) : i(e, o)) || r);
            return n > 3 && r && Object.defineProperty(e, o, r), r;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var r = t("GameEm"),
    s = t("EquipmentAnimal"),
    c = t("BoxGift"),
    p = t("CallBase"),
    l = cc._decorator,
    d = l.ccclass,
    u = l.property,
    h =
        (l.menu,
        (function (t) {
            i(e, t);
            function e() {
                var e = (null !== t && t.apply(this, arguments)) || this;
                e.callKind = r.CookingCallKey.node;
                e.checkId = "";
                e.aren = "0";
                e.equipmentList = [];
                e.cookViewDirIndex = [];
                e.curLv = -1;
                e.starCount = -1;
                e.foodId = "";
                return e;
            }
            e.prototype.onLoad = function () {
                EVUIEffView.on(EVUIEffView.callEquipment, this.callNode.bind(this), this);
                EVUIEffView.on(EVUIEffView.resetEquipment, this.resetData.bind(this), this);
                EVUIEffView.on(EVUIEffView.upLevelCooking, this.upLevel.bind(this), this);
                TaskGameEvent.on(TaskGameEvent.doFoodDevData, this.doDevCoolStatus.bind(this), this);
                this.resetData();
                this.setClick(!0);
            };
            e.prototype.resetSprite = function (t) {
                this.foodId = t;
                this.checkId = this.foodId;
                this.reCheck();
                if (this.equipmentList[1] && this.equipmentList[1].childrenCount > 0) {
                    var e = this.equipmentList[1],
                        o = e.children[e.childrenCount - 1];
                    if (o) {
                        var a = o.getComponent(cc.Sprite);
                        a && SpriteView.setFoodSprite(a, t);
                    }
                }
            };
            e.prototype.doDevCoolStatus = function (t, e, o, a) {
                if (e == this.checkId) {
                    var i = o + 2;
                    if (this.equipmentList[i]) {
                        var n = this.equipmentList[i].getComponent(s.default);
                        n && (a ? n.openCook() : n.closeCook());
                    }
                }
            };
            e.prototype.onDestroy = function () {
                this.setClick(!1);
                t.prototype.onDestroy.call(this);
                TaskGameEvent.offTarget(this);
                EVUIEffView.offTarget(this);
            };
            e.prototype.callNode = function (t, e, o, a) {
                e == this.callKind && a && a(this.node);
            };
            e.prototype.resetData = function () {
                for (var t = 0; t < this.equipmentList.length; t++) this.equipmentList[t].active = !1;
            };
            e.prototype.scaleNode = function () {
                for (var t = 0; t < this.equipmentList.length; t++)
                    this.equipmentList[t].active &&
                        0 == this.equipmentList[t].scale &&
                        CacheDataManager.getEquipDataStatusActive(this.checkId, t) &&
                        this.equipmentList[t].runAction(cc.scaleTo(0.1, 1).easing(cc.easeBackOut()));
            };
            e.prototype.upLevel = function (t, e, o, a) {
                if (e == this.checkId) {
                    var i = o;
                    if (i < this.equipmentList.length) {
                        this.curLv = i;
                        this.starCount = a;
                        if (i < 1) this.equipmentList[i].active = !0;
                        else {
                            this.equipmentList[0].active = !1;
                            for (var n = 1; n < this.equipmentList.length && n <= i; n++) {
                                this.checkLock(n);
                                this.checkLock(n + 1);
                            }
                        }
                    }
                    CacheDataManager.updateCostDataView = !0;
                }
            };
            e.prototype.checkLock = function (t) {
                var e = this,
                    o = t;
                if (this.equipmentList[o]) {
                    var a = this.equipmentList[o].active;
                    this.equipmentList[o].active = !0;
                    if (a != this.equipmentList[o].active) {
                        if (
                            o > 1 &&
                            !CacheDataManager.getEquipDataStatus(this.checkId, o) &&
                            !CacheDataManager.getEquipDataStatusActive(this.checkId, o)
                        ) {
                            var i = this.equipmentList[o];
                            o > 2 && EVUIEffView.emit(EVUIEffView.addTipCom, 1);
                            i.scale = 0;
                            this.playGiftBox(
                                this.equipmentList[o].parent,
                                cc.v2(this.equipmentList[o].position),
                                function () {
                                    "101" == e.checkId && 2 == t && QReport.sendOnce("100002");
                                    CacheDataManager.setEquipDataStatusActive(e.checkId, o, !0);
                                    i.runAction(cc.sequence([cc.scaleTo(0.1, 1.2), cc.scaleTo(0.1, 1)]));
                                    TaskGameEvent.emit(TaskGameEvent.unlockDevBox, e.checkId, o - 2);
                                }
                            );
                            CacheDataManager.setEquipDataStatus(this.checkId, o, !0);
                        }
                        this.equipmentList[o].scale =
                            o > 1 ? (CacheDataManager.getEquipDataStatusActive(this.checkId, o) ? 1 : 0) : 1;
                    }
                }
            };
            e.prototype.playGiftBox = function (t, e, o) {
                var a = this,
                    i = this.setLooperNode(QLooperNode.tag_boxDevGift, t, e);
                if (i) {
                    var n = i.getComponent(c.default);
                    n.play(o);
                    return n;
                }
                this.scheduleOnce(function () {
                    a.playGiftBox(t, e, o);
                }, 0.2);
            };
            e.prototype.setLooperNode = function (t, e, o) {
                var a = this,
                    i = QLooperNode.getNode(t);
                if (i) {
                    i.parent = e;
                    i.setPosition(o);
                    ParseTool.setSortIndex(i, 0);
                    return i;
                }
                this.scheduleOnce(function () {
                    a.setLooperNode(t, e, o);
                }, 0.2);
            };
            e.prototype._touchStart = function () {};
            e.prototype.touchNodeCancel = function () {
                this.curLv >= 0 &&
                    this.starCount >= 0 &&
                    (0 == this.curLv
                        ? EVUIEffView.emit(
                              EVUIEffView.openDlg,
                              this.foodId,
                              r.DlgKind.unLockDlg,
                              this.equipmentList[1].convertToWorldSpaceAR(cc.Vec2.ZERO),
                              !0
                          )
                        : EVUIEffView.emit(
                              EVUIEffView.openDlg,
                              this.foodId,
                              r.DlgKind.uplevel,
                              this.equipmentList[1].convertToWorldSpaceAR(cc.Vec2.ZERO),
                              !0
                          ));
                this.scaleNode();
            };
            e.prototype.reCheck = function () {
                if (this.equipmentList)
                    for (var t = 2; t < this.equipmentList.length; t++)
                        if (this.equipmentList[t]) {
                            var e = this.equipmentList[t].getComponent(s.default);
                            e && e.checkFoodId(this.foodId);
                        }
            };
            e.prototype.setClick = function (t) {
                for (var e = t ? "on" : "off", o = 0; o < this.equipmentList.length; o++) {
                    this.equipmentList[o][e](cc.Node.EventType.TOUCH_START, this._touchStart, this);
                    this.equipmentList[o][e](cc.Node.EventType.TOUCH_END, this.touchNodeCancel, this);
                    this.equipmentList[o][e](cc.Node.EventType.TOUCH_CANCEL, this.touchNodeCancel, this);
                }
            };
            e.prototype.updateLevel = function () {};
            n(
                [u({type: cc.Enum(r.CookingCallKey), displayName: "回调id", tooltip: ""})],
                e.prototype,
                "callKind",
                void 0
            );
            n([u({displayName: "检测id", tooltip: ""})], e.prototype, "checkId", void 0);
            n([u({displayName: "设备区域", tooltip: ""})], e.prototype, "aren", void 0);
            n([u([cc.Node])], e.prototype, "equipmentList", void 0);
            n([u([cc.Float])], e.prototype, "cookViewDirIndex", void 0);
            return n([d], e);
        })(p.default));
o.default = h;
